﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace KZ400B.Controls
{
    /// <summary>
    /// PositionLable.xaml 的交互逻辑
    /// </summary>
    public partial class PositionLable : UserControl
    {
        public static DependencyProperty InputWidthProperty = DependencyProperty.Register(
"InputWidth", typeof(int)
, typeof(PositionLable)
, new PropertyMetadata((int)int.MinValue, new PropertyChangedCallback(changeContentSize))
);
        static void changeContentSize(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PositionLable control = (PositionLable)d;
            control.gdAP.Width = control.InputWidth;
            control.spAP.Width = control.InputWidth - 5;
            control.labAxlePostion.Width = control.InputWidth - 5;
            
            
        }

        public int InputWidth
        {
            get { return (int)GetValue(InputWidthProperty); }
            set { SetValue(InputWidthProperty, value); }
        }


        public static DependencyProperty AxlePositionProperty = DependencyProperty.Register(
    "AxlePosition", typeof(double)
    , typeof(PositionLable)
     , new PropertyMetadata(Axle.DefaultPosition, new PropertyChangedCallback(OnPositionChange))
    );

        public double AxlePosition
        {
            get { return (double)GetValue(AxlePositionProperty); }
            set { SetValue(AxlePositionProperty, value); }
        }

        private static void OnPositionChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PositionLable control = (PositionLable)d;

            double pos = control.AxlePosition;
            control.labAxlePostion.Content = pos.ToString(MySetting.PositionDisDeciFormatter);

            //control.setBtnState_AxleNotRunning();
        }

        public PositionLable()
        {
            InitializeComponent();
        }
    }
}
